package com.am.lottery.view.menu

import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.automirrored.outlined.List
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationRail
import androidx.compose.material3.NavigationRailItem
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.am.lottery.view.home.HomeView
import com.am.lottery.view.list.ListView


object Menu {
    val items = listOf(
        MenuItem(
            title = "List",
            selectedIcon = Icons.AutoMirrored.Filled.List,
            unselectedIcons = Icons.AutoMirrored.Outlined.List,
            view = ListView
        ),
        MenuItem(
            title = "Home",
            selectedIcon = Icons.Filled.Home,
            unselectedIcons = Icons.Outlined.Home,
            view = HomeView
        ),
    )
}


@Composable
@Preview
fun menus() {
    var text by remember { mutableStateOf("Hello, World!") }
    var selectedItem by remember { mutableStateOf(Menu.items.first()) }
    val navigator = LocalNavigator.currentOrThrow
    // 内容区域，innerPadding用于考虑顶部栏等占用的空间
    Column(modifier = Modifier.padding()) {
        NavigationRail {
            Menu.items.forEach { item ->
                NavigationRailItem(
                    icon = {
                        Icon(
                            if (selectedItem == item) item.selectedIcon else item.unselectedIcons,
                            contentDescription = item.title
                        )
                    },
                    label = { Text(item.title) },
                    selected = selectedItem == item,
                    onClick = {
                        selectedItem = item
                        navigator.push(item.view)
                    }
                )
            }
        }
    }
}

data class MenuItem(
    val title: String,
    val selectedIcon: ImageVector,
    val unselectedIcons: ImageVector,
    val view: Screen
)